
var base_dep_rel_array={
		'SBV': '主谓关系',
		'VOB': '动宾关系',
		'IOB': '间宾关系',
		'FOB': '前置宾语',
		'DBL': '兼语',
	    'ATT': '定中关系',
		'ADV': '状中结构',
		'CMP': '动补结构',
		'COO': '并列关系',
		'POB': '介宾关系',
		'LAD': '左附加关系',
		'RAD': '右附加关系',
	    'IS': '独立结构',
		'HED': '核心关系',
		'WP': '标点符号'
		};

var base_attr_array = {
	'a' : '形容词',
	'ad' : '副形词',
	'an' : '名形词',
	'b' : '区别词',
	'c' : '连词',
	'd' : '副词',
	'e' : '叹词',
	'f' : '方位词',
	'g' : '语素词',
	'h' : '前接成分',
	'i' : '成语',
	'j' : '简称略语',
	'k' : '后接成分',
	'l' : '习用语',
	'm' : '数词',
	'n' : '名词',
	'nr' : '人名',
	'nh' : '人名',
	'nrf' : '姓',
	'nrg' : '名',
	'ns' : '地名',
	'nt' : '机构团体',
	'nz' : '专有名词',
	'nx' : '非汉字串',
	'o' : '拟声词',
	'p' : '介词',
	'q' : '量词',
	'r' : '代词',
	's' : '处所词',
	't' : '时间词',
	'u' : '助词',
	'v' : '动词',
	'vd' : '副动词',
	'vn' : '名动词',
	'w' : '标点符号',
	'x' : '非语素字',
	'y' : '语气词',
	'z' : '状态词',
	'ag' : '形语素',
	'bg' : '区别语素',
	'dg' : '副语素',
	'mg' : '数词性语素',
	'ng' : '名语素',
	'qg' : '量语素',
	'rg' : '代语素',
	'tg' : '时语素',
	'vg' : '动语素',
	'yg' : '语气词语素',
	'zg' : '状态词语素',
	'sos' : '开始词'
	};

// dependency 依存句法分析 * 不用管这个方法如何实现，只传入上述格式的json数据
function get_dependency(data){
	var url_obj   = {"nodes":[],"links":[]};
	var node_obj  = {};
	var links_obj = {};
	var dep_link_array = {};
	keywords_ret  = data["keywords"];
	if(keywords_ret instanceof Array){
		$('.dependency_chart').empty();
		deps = keywords_ret[0];
		node_obj = {"word": "root","pos": "","class": "root"};
		url_obj.nodes.push(node_obj);

		for(var i =0; i<deps.length; i++){
			node_obj = {};
			links_obj = {};
			node_obj["word"] = deps[i]["word"];
			node_obj["pos"] = base_attr_array[deps[i]["postag"]];
			node_obj["class"] = "term";
			links_obj["target"] = deps[i]["id"];
			links_obj["source"] = deps[i]["father_id"];
			links_obj["relation"] = deps[i]["dep_rel"];

			url_obj.nodes.push(node_obj);
			url_obj.links.push(links_obj);

			tmp_dep_rel   = deps[i]["dep_rel"];
			dep_link_array[tmp_dep_rel] = dep_link_array[tmp_dep_rel] || [];
			dep_link_array[tmp_dep_rel].push(i);
		}
		$('.dependency_text').children().empty();
		
		// dep_rel_tpl = '<a href="#" title="{dep_rel}">{dep_rel}-{dep_chn}</a>';
		dep_rel_tpl = '&nbsp;&nbsp; <button type="button" class="btn btn-green" style="margin-bottom: 5px;" title="{dep_rel}">{dep_rel}-{dep_chn}</button>';
		for( dep_rel in dep_link_array){
			var temp_dep_rel = dep_rel_tpl.replace(/{dep_rel}/g,dep_rel).replace('{dep_chn}',base_dep_rel_array[dep_rel]);
			$('.dependency_text').children().append(temp_dep_rel);
		}
	}

	url = encodeURIComponent(JSON.stringify(url_obj));
	DrawGraph(url);

	return;

	keywords_ret = data["keywords"];
	dep_rel_array  = [];
	dep_link_array = {};
	var width  = 0;
	var from_x = 0;
	var top_x  = 0;
	var top_y  = 0;
	var target_x = 0;
	var top    = 0;

	svg_html_tpl = '<div class="arc_arrow active {dep}"><svg version="1.1" baseProfile="full" xmlns="http://www.w3.org/2000/svg" width="{width}px" height="136px" viewBox="0 0 {width} 136">'+
                  '<defs><marker id="Arrow" markerWidth="5" markerHeight="5" viewBox="-6 -6 12 12" refX="-2" refY="0" markerUnits="strokeWidth" orient="auto"><polygon points="-2,0 -5,5 5,0 -5,-5" fill="#249a0d" stroke="transparent" stroke-width="2px"></polygon></marker></defs>'+
                  '<path d="M {from_x},130 Q {top_x},{top_y} {target_x},130" stroke="#249a0d" fill="none" stroke-width="2px" marker-end="url(#Arrow)"></path></svg>'+
                  '<p class="word_name word_name_vob" style="top:{top}px">{dep}</p></div>';
	word_root_tpl = '<div class="word_wrap"><span class="root">Root</span></div>';
	word_wrap_tpl = '<div class="word_wrap"><a href="##" class="word normal">{word}</a><span class="word_attr">{attr}</span></div>';
	if(keywords_ret instanceof Array){
		$('.dependency_chart').empty();
		$('.dependency_chart').append(word_root_tpl);
		deps = keywords_ret[0];
		for(var i = 0; i < deps.length; i++){
			var tmp_dep_rel   = deps[i]["dep_rel"];
			var tmp_father_id = deps[i]["father_id"];
			var tmp_id        = deps[i]["id"];
			var tmp_postag    = deps[i]["postag"];
			var tmp_word      = deps[i]["word"];
			direction = tmp_father_id > tmp_id ? 'reverse' : 'straight';
			//console.log(tmp_father_id+'+'+tmp_id);
			abs       = Math.abs(tmp_father_id - tmp_id);
			//console.log(direction+abs);
			if(direction == 'straight'){
				from_x = 25-abs;
				target_x = 25-abs+ 35*abs+0.6*abs*abs;
				target_x = abs>6 ? target_x + 20: target_x;
			}else{
				target_x = 25-abs;
				from_x   = 25-abs+ 35*abs+0.6*abs*abs;
				from_x   = abs>6 ? form_x + 20 : from_x;
			}
			if(tmp_father_id == 0){
				target_x += 30;
			}
			top   = 90-10*abs;
			top   = Math.max(-3,top);
			top_x = (from_x + target_x)/2;
			top_y = 120-20*abs;
			top_y = Math.max(-100,top_y);

			width = Math.abs(from_x-target_x) + 35;


			var tmp_svg_html  = svg_html_tpl.replace(/{dep}/g,tmp_dep_rel).replace(/{width}/g,width).replace('{from_x}',from_x).replace('{target_x}',target_x).replace('{top_x}',top_x).replace('{top_y}',top_y).replace('{top}',top);
			var temp_word_wrap = word_wrap_tpl.replace('{word}',tmp_word).replace('{attr}',base_attr_array[tmp_postag]);
			$('.dependency_chart').append(temp_word_wrap);
			if(direction == 'straight'){
				$($('.dependency_chart .word_wrap').get(tmp_father_id)).append(tmp_svg_html);
			}else{
				$($('.dependency_chart .word_wrap').get(tmp_id)).append(tmp_svg_html);
			}
			dep_link_array[tmp_dep_rel] = dep_link_array[tmp_dep_rel] || [];
			dep_link_array[tmp_dep_rel].push(i);
		}
		$('.dependency_text').children().empty();
		dep_rel_tpl = '<a href="#" title="{dep_rel}">{dep_rel}-{dep_chn}</a>';
		for( dep_rel in dep_link_array){
			var temp_dep_rel = dep_rel_tpl.replace(/{dep_rel}/g,dep_rel).replace('{dep_chn}',base_dep_rel_array[dep_rel]);
			$('.dependency_text').children().append(temp_dep_rel);
		}


	}
	// 
}